<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
if (isset($_SESSION['lang']))
    require_once "./language_files/viewMembers_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/viewMembers_en.php";
?>
<html>
    <head>
        <title></title>
        <link href="style3.css" rel="stylesheet" type="text/css" />
        <?php include 'jquery.php'; ?>
        <script type="text/javascript" src="functions.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                check_top();
            });
        </script>
    </head>
    <?php
    require_once "functions.php";
//checks on wether the conference id was sent or not
    If (isset($_GET['conference_id'])) {
// establish a database connection
        // save the conference id in a variable
        $conference_id = mysql_real_escape_string($_GET['conference_id']);
        $get_name = mysql_query("Select long_name From conference Where conference_id = '$conference_id'") or die(mysql_error());
        $Get_name = mysql_fetch_assoc($get_name);
        $long = formatText_safe($Get_name['long_name']);
        echo"</br><span class=breadcrumbs><a href='subscriberConferencePage.php?conference_id={$conference_id}'>" . $long . "</a>" . " > " . $lang['view'] . "</span> </br>";
        echo "<h1>{$long}</h1>";
        // execute the query that gets the first , last name of the member as well as his id
        $select_members = mysql_query("SELECT DISTINCT first_name, last_name , m.member_id FROM member m 
                INNER JOIN member_privileges mp ON (m.member_id = mp.member_id)
                WHERE  mp.conference_id= '$conference_id' 
                ORDER BY first_name ASC 
                 ")
                or die(mysql_error());

        if (mysql_num_rows($select_members) > 0) {

            echo '<table width="100%">
        <tr>
        <td style="background-color:#003366; color:white; text-align:center"><b>Member</b></td>
        <td style="background-color:#003366; color:white; text-align:center"><b>Role</b></td>
        </tr>';
//display  each member's name in a hyperlink whenever the user clicks on this link he will be redirected to the profile page of this member
            while ($row = mysql_fetch_assoc($select_members)) {
                $f_name = formatText_safe($row['first_name']);
                $l_name = formatText_safe($row['last_name']);
                $memberID = $row['member_id'];
                $role = mysql_query("SELECT p.role from privileges p INNER JOIN member_privileges mp 
                    ON (mp.privileges_id = p.privileges_id)
                    WHERE mp.conference_id = $conference_id AND mp.member_id = $memberID
                ") or die(mysql_error());
                $author = "";
                $organizer = "";
                $reviewer = "";
                while ($r = mysql_fetch_assoc($role)) {
                    $rl = $r['role'];
                    if ($rl == 'author') {
                        $author = 'author';
                    }
                    if ($rl == 'organizer') {
                        $organizer = 'organizer';
                    }
                    if ($rl == 'reviewer') {
                        $reviewer = 'reviewer';
                    }
                    if($rl == 'attendee') {
                        $attendee = 'attendee';
                    }
                }
                $role = $author ." ". $organizer ." ". $reviewer ." ". $attendee;
                echo '<tr><td><a href="main.php?page=profilePage.php&member_id=' . $memberID . '"target="_blank">' . $f_name . " " . $l_name . "</a>
                 </td><td>$role</td></tr>\n";
            }

            echo '</table>';

            mysql_close();
        } else {
            echo $lang['no_members'];
        }
    }
    ?>